var app = angular.module('myapp', []);
app.controller('personalinfo.ctrl', ['$scope', '$http', function ($scope, $http) {
    $scope.saveSuccess=false;
    $http.get('/user/isLogin')
        .then(function (res) {
            if (res.data.status) {
                var username = res.data.data[0].username;
                $http.post('/user/getuser',{username:username}).then(function (res) {
                    $scope.username = res.data.data[0].username;
                    $scope.name = res.data.data[0].name;
                    $scope.email = res.data.data[0].email;
                    $scope.phone = res.data.data[0].phone;
                });
            }
        });
    $scope.Update = function () {
        var userList = {
            username: $scope.username,
            name: $scope.name,
            email: $scope.email,
            phone: $scope.phone
        };
        $http.post('/user/updateinfo', userList).then(function (res) {
            console.log(res.data.msg);
            if (res.data.msg=='success'){
                $scope.saveSuccess=true;
                setInterval(function () {
                    location.href='../personal.html';
                },300)
            }else {
                $scope.saveSuccess=false;
            }
        });
    };
}]);